package com.leetcode.No0053;

import org.junit.Test;

public class Solution2 {
    public int maxSubArray(int[] nums) {
        int pre = 0;
        int ans = Integer.MIN_VALUE;
        for (int num : nums) {
            pre = Math.max(pre + num, num);
            ans = Math.max(pre, ans);
        }
        return ans;
    }

    @Test
    public void test() {
        int[] nums = {1,2,-1,-2,2,1,-2,1,4,-5,4};
        System.out.println(maxSubArray(nums));
    }

}
